package cn.tedu.shopol.taojin.util;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

@Data
@Accessors(chain = true)
public class R<T> implements Serializable {
    private Integer state;
    private String message;
    private T data;

    public static R ok() {

        return new R().setState(State.OK);
    }

    public static <T> R<T> ok(T data) {

        return R.ok().setData(data);
    }

    public static R failure(Integer state,String message){

        return new R().setState(state).setMessage(message);
    }

    public static R failure(Integer state,Throwable e){

        return failure(state,e.getMessage());
    }

    public interface State {
        Integer OK = 2000;
        Integer ERR_PHONE_DUPLICATE = 4000;
        Integer ERR_INSERT = 4010;
        Integer ERR_INVALID_PARAMETER = 4020;
    }
}
